package com.hawthorn.admin.repository.provider;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.builder.annotation.ProviderMethodResolver;

import java.util.Map;

/**
 * <p>todo 部门维护provider</p >
 * @author: fengliye@expservice.com.cn
 * @created: 2022/6/22 17:01
 * @version v1.0.1
 */
@Slf4j
public class SysDeptSqlProvider implements ProviderMethodResolver {

  public static String listDepts(Page<Map<String, Object>> page, String conditions)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	id,\n ");
    sql.append(" 	company_id companyId,\n ");
    sql.append(" 	dcode,\n ");
    sql.append(" 	dname,\n ");
    sql.append(" 	sname,\n ");
    sql.append(" 	ename,\n ");
    sql.append(" 	pid,\n ");
    sql.append(" 	level,\n ");
    sql.append(" 	dc,\n ");
    sql.append(" 	dept_type deptType,\n ");
    sql.append(" 	biz_type bizType,\n ");
    sql.append(" 	status,\n ");
    sql.append(" 	biz_status bizStatus \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_dept\n ");
    sql.append(" where");
    sql.append(conditions);
    return sql.toString();
  }

  public static String findByDcodeAndDname(String dcode,String dname)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(" 	count( id ) \n ");
    sql.append(" from\n ");
    sql.append(" 	sys_dept \n ");
    sql.append(" where\n ");
    sql.append(" 	dcode = " + "'" + dcode + "'");
    sql.append(" 	or dname = " + "'" + dname + "'");
    return sql.toString();
  }

  public static String exportDepts(String fields, String conditions)
  {
    StringBuffer sql = new StringBuffer();
    sql.append(" select\n ");
    sql.append(fields);
    sql.append(" from sys_dept");
    sql.append(" where");
    sql.append(conditions);
    sql.append("  order by dcode asc \n ");
    return sql.toString();
  }
}
